﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OperaHouse.Business.Contacts;
using OperaHouse.Web.Models;
using OperaHouse.Domain.Contacts;

namespace OperaHouse.Web.Controllers
{
    public partial class HomeController : Controller
    {

        #region Fields
        private readonly IContactService _contactService;
        #endregion

        #region Ctor
        public HomeController(IContactService contactService)
        {
            this._contactService = contactService;
        }
        #endregion

        #region Action
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Info()
        {
            return PartialView();
        }

        public ActionResult ContactUs()
        {
            ContactModel model = new ContactModel();
            return View(model);
        }

        [HttpPost, ValidateInput(false)]
        public ActionResult ContactUs(ContactModel model)
        {
            if (ModelState.IsValid)
            {
                Contact contact = new Contact();
                contact.Name = model.Name;
                contact.Phone = model.Phone;
                contact.Address = model.Address;
                contact.Email = model.Email;
                contact.Body = model.Body;
                contact.CreatedOn = DateTime.Now;
                _contactService.InsertContact(contact);

                return RedirectToAction("Thankyou");
            }
            return View(model);
        }

        public ActionResult Thankyou()
        {
            return View();
        }
        #endregion
    }
}
